package com.kiko.education.controller;

import com.kiko.education.mapper.ClassMapper;
import com.kiko.education.mapper.CollegeMapper;
import com.kiko.education.model.Course;
import com.kiko.education.model.User;
import com.kiko.education.service.CourseService;
import com.kiko.education.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;
import java.util.Map;

@Controller
public class InfoController {
    @Autowired
    private UserService userService;
    @Autowired
    private CourseService courseService;
    @Autowired
    private ClassMapper classMapper;
    @Autowired
    private CollegeMapper collegeMapper;
    //反馈教师的信息
    public Model getTeacherInfo(User user, Model model){
        String college = collegeMapper.getCollegeNameByID(user.getCollegeID());
        String className = classMapper.getClassNameByID(user.getID());
        model.addAttribute("college", college);
        model.addAttribute("userID", user.getUserID());
        model.addAttribute("sex", user.getSex());
        model.addAttribute("className", className);
        return model;
    }
    //反馈学生信息
    public Model getStudentInfo(User user,Model model){
        String college = collegeMapper.getCollegeNameByID(user.getCollegeID());
        model.addAttribute("college", college);
        model.addAttribute("userID", user.getUserID());
        model.addAttribute("sex", user.getSex());
        model.addAttribute("userName", user.getUserName());
        return model;
    }
    //登录
    @RequestMapping(value = "/loginIn", method = RequestMethod.POST)
    public String LoginHtml(@RequestParam("userID") String userID,
                            @RequestParam("userPassword") String userPassword,
                            Model model){
        System.out.println(userID+" "+userPassword);
        User user = userService.getByUserID(userID);
        if(user != null && user.getUserPassword().equals(userPassword)){
            if(userID.contains("admin")){
                return "index";
            }
            else if(userID.contains("T")){
                return "teacherInfo";
            }
            else if(userID.contains("F")){
                return "FInfo";
            }
            else if(userID.contains("B")){
                model = getTeacherInfo(user,model);
                return "BInfo";
            }
            else if(userID.contains("J")){
                return "JInfo";
            }
            else {
                model = getStudentInfo(user,model);
                return "stuIndex";
            }
        }
        else {
            return "login";
        }
    }
}


